package com.rongma.waterdrop.utils;

import com.rongma.waterdrop.exception.WrongScoreException;

/**
 * Created by RongMa on 16/6/11.
 */

public class ScoreUtil
{
    private ScoreUtil(){}

    private static String[] ranks = new String[]{"码畜 Ⅲ级","码畜 Ⅱ级","码畜 Ⅰ级",
            "码奴 Ⅲ级","码奴 Ⅱ级","码奴 Ⅰ级",
            "码农 Ⅲ级","码农 Ⅱ级","码农 Ⅰ级",
            "IT民工 Ⅲ级","IT民工 Ⅱ级","IT民工 Ⅰ级",
            "攻城狮 青铜Ⅴ","攻城狮 青铜Ⅳ","攻城狮 青铜Ⅲ","攻城狮 青铜Ⅱ","攻城狮 青铜Ⅰ",
            "攻城狮 白银Ⅴ","攻城狮 白银Ⅳ","攻城狮 白银Ⅲ","攻城狮 白银Ⅱ","攻城狮 白银Ⅰ",
            "攻城狮 黄金Ⅴ","攻城狮 黄金Ⅳ","攻城狮 黄金Ⅲ","攻城狮 黄金Ⅱ","攻城狮 黄金Ⅰ",
            "攻城狮 白金Ⅴ","攻城狮 白金Ⅳ","攻城狮 白金Ⅲ","攻城狮 白金Ⅱ","攻城狮 白金Ⅰ",
            "攻城狮 钻石Ⅴ","攻城狮 钻石Ⅳ","攻城狮 钻石Ⅲ","攻城狮 钻石Ⅱ","攻城狮 钻石Ⅰ",
            "攻城狮 王者Ⅴ","攻城狮 王者Ⅳ","攻城狮 王者Ⅲ","攻城狮 王者Ⅱ","攻城狮 王者Ⅰ","无敌"};

    private static String getRankByScore(long score) throws WrongScoreException {
        String rank = "";
        if(score < 0)
        {
            throw new WrongScoreException("积分数值不可以小于0!");
        }
        else
        {
            for(int i = 0 ; i < ranks.length ; i++)
            {
                if(score < 100 * Math.pow(1.5,i))
                {
                    rank = ranks[i];
                    LogUtils.show("i:"+i);
                    LogUtils.show("rank:"+rank);
                    break;
                }
            }
        }
        return "级别:"+rank;
    }

    public static String getRankByScoreAndTime(long score,long time) throws WrongScoreException {
         try
         {
             long newScore = (long) Arith.add(score,Arith.div(time,100,0));
             return getRankByScore(newScore);
         }
         catch (IllegalAccessException e)
         {
             e.printStackTrace();
         }
         return "";
    }
}
